import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;

public class Gestor {
	
	public void cargarTarjeta(int valor) throws FileNotFoundException, IOException, ClassNotFoundException{
				
		Tarjeta temp = new Tarjeta();
		Lector templec = new Lector();
		temp=templec.Leer();
		String ladireccion=templec.getGlobalPath();
		if(temp.get_activo()){	
			temp.set_valor(temp.get_valor()+valor);	
			ObjectOutputStream esctarj =new ObjectOutputStream(new FileOutputStream(ladireccion));	
			esctarj.writeObject(temp);
			esctarj.close();
			JOptionPane.showMessageDialog(null, "Tarjeta Cargada");	
		}		
		else{
			JOptionPane.showMessageDialog(null, "Error: La Tarjeta Esta Desactivada");
		}	
		
	}

	public void mostrarSaldo() throws FileNotFoundException, IOException, ClassNotFoundException{
		Lector temp = new Lector();
		Tarjeta tartemp = new Tarjeta();
		tartemp=temp.Leer();
		JOptionPane.showMessageDialog(null, "SALDO: "+String.valueOf(tartemp.get_valor()));
	}
	
	public void activarTarjeta() throws FileNotFoundException, IOException, ClassNotFoundException{
			
			Lector tempLec = new Lector();
			Tarjeta temp = new Tarjeta();
			temp=tempLec.Leer();
			String path=tempLec.getGlobalPath();
			if(temp.get_activo()){
				JOptionPane.showMessageDialog(null, "Error: La Tarjeta Ya Esta Activa");
			}else
			{			
				temp.set_activo(true);
				ObjectOutputStream esctarj =new ObjectOutputStream(new FileOutputStream(path));	
				esctarj.writeObject(temp);
				esctarj.close();
				JOptionPane.showMessageDialog(null, "La Tarjeta Ha Sido Activada");
			}

	}
	
	
}
